version 13.0
log using "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\figure1_appendix.log", replace

#delimit ;


*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      figure1_appendix.do                             *;
*       Date:           January 14, 2019                                *;
*       Author:         MRG/CC                                          *;
*       Purpose:      	Produce Figure 1 in Online appendix for It's    *;
*                       Not Only What You Say, It's Also How You Say    *;
*                       It: The Strategic Use Of Campaign Sentiment.    *;
*                       Journal of Politics. Forthcoming.               *;
* 	    Input File:     sentiment.dta                                   *;
*       Output File:    figure1_appendix.log                            *;
*       Data Output:    none                                            *;             
*       Previous file:  sentiment.dta                                   *;
*       Machine:        desktop/laptop                     				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*        Load data                                                      *;
*     ****************************************************************  *;

use "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\replication\data_analysis\sentiment.dta", clear;

set more off;


*     ****************************************************************  *;
*       Declare data to be panel, where the panel is based on language  *;
*     ****************************************************************  *;

xtset language;

xtsum positive_sentiment;

*     ****************************************************************  *;
*       Generate additional variables that we will need for our         *;
*       analysis.                                                       *;
*     ****************************************************************  *;

gen incumbent_inflation_l = incumbent*inflation_l;
label var incumbent_inflation "incumbent*inflation_l";
gen incumbent_unemployment_l = incumbent*unemployment_l;
label var incumbent_unemployment_l "incumbent*unemployment_l";
gen incumbent_pm = incumbent*pm;
label var incumbent_pm "incumbent*pm";
gen incumbent_fm = incumbent*fm;
label var incumbent_fm "incumbent*fm";
gen left_right2=left_right*left_right;
label var left_right2 "left_right*left_right";
gen extremist = 0;
replace extremist=1 if family_id ==14 | family_id==40;
replace extremist = . if family_id==.;
label var extremist "1 if communist/socialist or far right, 0 otherwise";
gen extremist2 = 0;
replace extremist2=1 if family_id ==14 | family_id==40 | family_id==19;
replace extremist2 = . if family_id==.;
label var extremist2 "1 if communist/socialist, far right, or greens, 0 otherwise";
gen extremist_inflation_l=extremist*inflation_l;
label var extremist_inflation "extremist*inflation_l";
gen extremist_unemployment_l=extremist*unemployment_l;
label var extremist_unemployment_l "extremist*unemployment_l";

tabulate language, gen(l);

sum positive_emotion negative_emotion positive_sentiment;

*     ****************************************************************  *;
*      Change graph scheme	                                            *;
*     ****************************************************************  *;

*ssc install scheme-burd, replace;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       Produce Figure 1 in the Appendix                                *;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Panel A                                                         *;
*     ****************************************************************  *;

histogram positive_emotion, xtitle("Positive Words Scores") scheme(burd);

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig1a_appendix.pdf", replace;

*     ****************************************************************  *;
*       Panel B                                                         *;
*     ****************************************************************  *;

histogram negative_emotion, xtitle("Negative Words Scores") scheme(burd);

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig1b_appendix.pdf", replace;

*     ****************************************************************  *;
*       Panel C                                                         *;
*     ****************************************************************  *;

histogram positive_sentiment, xtitle("Positive Sentiment") scheme(burd);

graph export "C:\Users\mgolder\Dropbox\campaign_sentiment_paper\fig1c_appendix.pdf", replace;
   
*     ****************************************************************  *;
*       Replication complete                                            *;
*     ****************************************************************  *;

log close;

clear;






